package io.jjz.dao;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * Author       : 蒋俊钊 80256973
 * Date         : 2019/12/20
 * Copyright    (C) ChinaMerchantsBank
 */
public abstract class HBaseDao {

    private static final Logger LOGGER = LoggerFactory.getLogger(HBaseDao.class);

    @Resource(name = "configuration")
    private Configuration conf;

    protected Connection connection;

    //@Scheduled(fixedRate = 23 * 60 * 60 * 1000)
    private void refreshConn() throws IOException {
        if (connection != null) {
            connection.close();
            connection = null;
        }
        LOGGER.info("自动刷新.........");
        //UserGroupInformation.loginUserFromKeytab(HBaseConfig.userPrincipal, HBaseConfig.userKeytabPath);
        this.connection = ConnectionFactory.createConnection(conf);
    }

    /*@PostConstruct
    public void init() throws IOException {
        LoginUtil.setJaasConf(HBaseConfig.ZOOKEEPER_DEFAULT_LOGIN_CONTEXT_NAME, HBaseConfig.userPrincipal, HBaseConfig.userKeytabPath);
        UserGroupInformation.setConfiguration(conf);
    }*/
}
